package com.xuebank.nfe.nfecar.utils;

import android.app.Activity;
import android.app.Dialog;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.FeatureInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.hardware.camera2.CameraManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Looper;
import android.provider.ContactsContract;
import android.support.annotation.RequiresApi;
import android.telephony.SmsManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.FocusFinder;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.Toast;


import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import com.wzn.libaray.event.RxBus;
import com.wzn.libaray.utils.cache.SharedPreferencesUtil;
import com.xuebank.nfe.nfecar.MainActivity;
import com.xuebank.nfe.nfecar.MyApplication;
import com.xuebank.nfe.nfecar.R;
import com.xuebank.nfe.nfecar.activity.CameraActivity;
import com.xuebank.nfe.nfecar.activity.ReleaseActivity;
import com.xuebank.nfe.nfecar.globals.Constants;
import com.xuebank.nfe.nfecar.model.JSEvent;
import com.xuebank.nfe.nfecar.model.RefreshHtml;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Map;

import rx.functions.Action1;

import static com.xuebank.nfe.nfecar.utils.CacheUtils.getString;

/*import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;*/
@SuppressWarnings("Deprecated")
public class XueBankUtils {

    //    private AMapLocationClientOption mLocationOption = null;
    //    private AMapLocationClient mLocationClient = null;

    private static String TABLENAME = "xuebank";
    private static String VALUE     = "value";
    private static String KEY       = "key";
    private Activity       thisActivity;
    private callBack       callback;
    private LaunchCallBack launchCallBack;
    private JSONObject locJson;
    private WebView        mWebView;
    private String result = "";

    private String        country;
    private String        province;
    private String        city;
    private String        district;
    private String        street;
    private String        streetNum;
    private double        latitude;
    private double        longitude;
    private String        name;
    private String        adCode;
    private JSONObject    json;
    private Camera        mCamera;
    private SensorManager sensorManager;
    private Sensor        sensor;
    private              float timestamp = 0;
    private              float angle[]   = new float[3];
    private static final float NS2S      = 1.0f / 1000000000.0f;
    private              float gx        = 0, gy = 0, gz = 0;
    private SensorEventListener mSensorEventListener;
    private int accuracy = 2;
    private String phoneNum;
    private IWXAPI iwxapi;
    private Intent intent;
    private byte[] bytes;
    private Dialog mShareDialog;

    public XueBankUtils(Activity thisActivity) {
        this.thisActivity = thisActivity;

    }

    //    private String requestLocation() {
    //
    //        return getJson(locJson);
    //    }


    private String getEmptyString(String str) {
        if (TextUtils.isEmpty(str)) {
            str = "";
        }
        return str;
    }

    public interface callBack {
        void onCallBack(String data);
    }

    public interface LaunchCallBack {
        void onLaunchCallBack(String result);
    }

    public void setCallback(LaunchCallBack callback) {
        this.launchCallBack = callback;
    }







    @RequiresApi(api = Build.VERSION_CODES.M)
    public void doBridgeHandler(String data, final callBack callback) {
        this.callback = callback;
        iwxapi = WXAPIFactory.createWXAPI(thisActivity, Constants.WECHAT_APP_ID, true);
        iwxapi.registerApp(Constants.WECHAT_APP_ID);
        try {
            JSONObject jsonObject = new JSONObject(data);
            String send_action = jsonObject.getString("action");
            JSONObject send_data = jsonObject.getJSONObject("data");

            //            if (send_action.equals("LocalLocation")) {
            //                result = requestLocation();
            //                System.out.println("我是定位" + 1111);
            ////            } else if (send_action.equals("LoginVerification")) {
            ////                requestLocation(); //定位
            //            } else {
            switch (send_action) {
                case "LoginVerification":

                    String callBackURL = (String) send_data.get("callBackURL");
                    String callBackParams = (String) send_data.get("callBackParams");
                    String functionName = jsonObject.getString("functionName");
                    String[] split1 = callBackParams.split("&");
                    String s = split1[0];
                    String s1 = split1[1];
                    break;

                case "ShareByUI":{
                    Log.e("test", "2222");
                    String shareTitle = (String) send_data.get("title");
                    String shareContent = (String) send_data.get("content");
                    String shareUrlStr = (String) send_data.get("urlStr");
                    final String shareImageUrl = (String) send_data.get("imageUrl");

                    WXWebpageObject webPage = new WXWebpageObject();
                    webPage.webpageUrl = shareUrlStr;
                    final WXMediaMessage wxMsg = new WXMediaMessage(webPage);
                    wxMsg.title = shareTitle;
                    wxMsg.description = shareContent;
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                Bitmap thumb = BitmapFactory.decodeStream(new URL(shareImageUrl).openStream());
                                Bitmap scaledBitmap = Bitmap.createScaledBitmap(thumb, 120, 150, true);
                                wxMsg.thumbData = AppUtils.bmpToByteArray(scaledBitmap, true);
                                SendMessageToWX.Req req = new SendMessageToWX.Req();
                                req.transaction = String.valueOf(System.currentTimeMillis());
                                req.message = wxMsg;
                                Looper.prepare();
                                if (mShareDialog == null) {
                                    initShareDialog(req);
                                }
                                mShareDialog.show();
                                Looper.loop();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }).start();

                }
                    break;
                case "LoginStatus": {//长登录
                }
                break;
                case "WX_LoginAuthBlock":{//微信登录
                    final String[] code = new String[1];
                     SendAuth.Req req = new SendAuth.Req();
                    req.scope = "snsapi_userinfo";
                    req.state = "wechat_sdk_demo_test";
                    iwxapi .sendReq(req);

                    RxBus.getDefault()
                .toObserverable(JSEvent.class)
                .subscribe(new Action1<JSEvent>() {
                    @Override
                    public void call(JSEvent jsEvent) {
                        code[0] =  jsEvent.getData();


                        json = new JSONObject();
                        try {
                            json.put("code", "0");
                            json.put("error", "");
                            json.put("data",code[0]);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        result = json.toString();
                        callback.onCallBack(result);

                    }
                });

                }
                case "QueryKeyJsonString": {
                    String key = (String) send_data.get("key");
                    result = getString(key);
                    json = new JSONObject();
                    json.put("isExist", result == null ? "0" : "1");
                    result = getJson(json);
                    if (callback != null) {
                        callback.onCallBack(result);
                    }
                }
                break;
                case "SelectJsonString": {//查询存储
                    String key = (String) send_data.get("key");
                    String str = getString(key);
                    if (str == null) {
                        json = new JSONObject();
//                        json.put("json", JSON.parse(""));
                        result = getErrorJson(json);
                    } else {
                        json = new JSONObject();
                        Object obj = JSONObject.quote(str);
                        json.put("json", obj);
                        result = getJson(json);
                    }
                    if (callback != null) {
                        callback.onCallBack(result);
                    }
                }
                break;
                case "OpenICBCWithID": {
                    String type = (String) send_data.get("type");
                    if (type.equals("lbsGame")) {
                        json = new JSONObject();
                        json.put("code", "0");
                        json.put("error", "");
                        result = json.toString();
                        if (callback != null) {
                            callback.onCallBack(result);
                        }
                    }

                }
                break;

                case "OSVersion":
                    result = "Android" + Build.VERSION.RELEASE;
                    if (callback != null) {
                        callback.onCallBack(result);
                    }
                    break;
                //                    case "NetworkingMonitor":
                //                        NetUtils.isNetworkAvailable()
                //                        break;
                case "AddCalendarEvent":
                    break;
                case "PublishNote"://车记进发布
                    if (send_data.get("type").toString().contains("add")) {
                        Intent intent = new Intent(thisActivity, CameraActivity.class);
                        thisActivity.startActivity(intent);
                    } else {

                        String noteId =(String) send_data.get("noteId").toString();
                        Boolean isTabBar =(Boolean)send_data.get("isTabBar");
                        Boolean isPublish = (Boolean) send_data.get("isPublish");
                        Intent intent = new Intent(thisActivity, ReleaseActivity.class);

                        intent.putExtra("noteId",noteId);
                        intent.putExtra("isPublish", isPublish);
                        intent.putExtra(Constants.LOGIN_RELEASE, Constants.DRAFT);
                        thisActivity.startActivity(intent);
                    }





                    break;
                case  "UpdateJsonString":

                    JSONObject sass = (JSONObject) send_data.get("json");
                    JSONObject dddd = new JSONObject(sass.toString());

                   String sssss =  (String) dddd.get("islogin");
                    SharedPreferencesUtil.getInstance(MyApplication.myApplicationContext).applyString(MainActivity.Companion.getIS_LONGIN(),sssss);
                    break;
                case "RecoderRefresh":
                    intent = thisActivity.getIntent();
                    boolean isRefresh = (boolean) send_data.get("isRefresh");
                    CacheUtils.putBoolean("isRefresh", isRefresh);

                    if (isRefresh == true) {
                        intent.putExtra("isRefresh", isRefresh);
                        thisActivity.setResult(NfeConstants.REFRESH_OK,intent);
                    }
                    break;
                case "RetainNavigationBar":
                    String webUrl = (String) send_data.get("webUrl");
                    boolean isReload = (boolean) send_data.get("isReload");
                    String title = (String) send_data.get("title");
                    this.intent = new Intent(thisActivity, FocusFinder.class);
                    this.intent.putExtra("webUrl", webUrl);
                    this.intent.putExtra("isReload", isReload);
                    this.intent.putExtra("title", title);
                    thisActivity.startActivityForResult(this.intent, NfeConstants.REFRESH);
                    break;
                case "OpenTelephone"://调用打电话
                    String tel = (String) send_data.get("tel");
                    Intent telIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + tel));
                    telIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    thisActivity.startActivity(telIntent);
                    break;
                case "ObtainICBCEnvironment":
                    json = new JSONObject();
                    json.put("contactType", "2001");
                    result = getJson(json);
                    if (callback != null) {
                        callback.onCallBack(result);
                    }
                    break;
                //获取设备类型
                case "DeviceType":
                    String phoneBrand = Build.BRAND;
                    String phoneModel = Build.MODEL;
                    String deviceType = phoneBrand + phoneModel;
                    json = new JSONObject();
                    json.put("type", deviceType);
                    result = getJson(json);
                    if (callback != null) {
                        callback.onCallBack(result);
                    }
                    break;
                //获取设备运营商
                case "DeviceCarrier":
                    String operators = AppUtils.getOperators(thisActivity);
                    json = new JSONObject();
                    json.put("carrier", operators);
                    result = getJson(json);
                    if (callback != null) {
                        callback.onCallBack(result);
                    }
                    break;
                //获取App版本号
                case "ApplicationVersin":
                    int code = AppUtils.getAppVersionCode(thisActivity);
                    json = new JSONObject();
                    json.put("version", String.valueOf(code));
                    result = getJson(json);
                    if (callback != null) {
                        callback.onCallBack(result);
                    }
                    break;
                //提供手电筒组件
                case "ManageFlashLight":
                    String isOpen = (String) send_data.get("isOpen");
                    json = new JSONObject();
                    CameraManager manager = (CameraManager) thisActivity.getSystemService(Context.CAMERA_SERVICE);
                    //打开手电筒
                    if (isOpen == "0") {
                        if (isM()) {
                            try {
                                manager.setTorchMode("0", true);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                            final PackageManager pm = thisActivity.getPackageManager();
                            final FeatureInfo[] features = pm.getSystemAvailableFeatures();
                            for (final FeatureInfo f : features) {
                                if (PackageManager.FEATURE_CAMERA_FLASH.equals(f.name)) { // 判断设备是否支持闪光灯
                                    if (null == mCamera) {
                                        mCamera = Camera.open();
                                    }
                                    final Camera.Parameters parameters = mCamera.getParameters();
                                    parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
                                    mCamera.setParameters(parameters);
                                    mCamera.startPreview();
                                } else {   //设备不支持
                                    json.put("isOpen", "0");
                                    getErrorJson(json);
                                    if (callback != null) {
                                        callback.onCallBack(result);
                                    }
                                }
                            }
                        }
                    } else {     //关闭手电筒
                        if (isM()) {
                            try {
                                manager.setTorchMode("0", false);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                            if (mCamera != null) {
                                mCamera.stopPreview();
                                mCamera.release();
                                mCamera = null;
                            }
                        }

                    }
                    break;
                //获取当前用户信息
                case "CacheUserInfo":
                    JSONObject result1 = send_data.getJSONObject("result");
                    String userIdLong = result1.getString("userIdLong");
                    json = new JSONObject();
                    json.put("custId", userIdLong);
                    result = getJson(json);
                    if (callback != null) {
                        callback.onCallBack(result);
                    }
                    break;
                case "PopViewController":
                    if (!thisActivity.isFinishing()) {
                        thisActivity.setResult(NfeConstants.REFRESH_OK, intent);
                        thisActivity.finish();
                    }
                    break;
                //获取系统通讯录
                case "OpenAddressBookUI":
                    this.intent = new Intent(Intent.ACTION_PICK);
                    this.intent.setType(ContactsContract.Contacts.CONTENT_TYPE);//vnd.android.cursor.dir/contact
                    thisActivity.startActivityForResult(this.intent, NfeConstants.PICK_CONTACT);
                    json = new JSONObject();
                    result = getJson(json);
                    if (callback != null) {
                        callback.onCallBack(result);
                    }
                    break;
                //开始监听陀螺仪组件
                case "StartMonitoringGyro":
                    sensorManager = (SensorManager) thisActivity.getSystemService(Context.SENSOR_SERVICE);
                    //获取陀螺仪
                    sensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
                    //注册陀螺仪
                    sensorManager.registerListener(mSensorEventListener, sensor, SensorManager.SENSOR_DELAY_NORMAL);
                    //                            if(gz != 0){
                    //                                Log.d("================", "anglex------------>" + (gz - anglez));
                    //                            }
                    mSensorEventListener = new SensorEventListener() {
                        @Override
                        public void onSensorChanged(SensorEvent event) {
                            if (event.accuracy != 0) {
                                int type = event.sensor.getType();
                                switch (type) {
                                    case Sensor.TYPE_GYROSCOPE:
                                        if (timestamp != 0) {
                                            final float dT = (event.timestamp - timestamp) * NS2S;
                                            angle[0] += event.values[0] * dT;
                                            angle[1] += event.values[1] * dT;
                                            angle[2] += event.values[2] * dT;

                                            float anglex = (float) Math.toDegrees(angle[0]);
                                            float angley = (float) Math.toDegrees(angle[1]);
                                            float anglez = (float) Math.toDegrees(angle[2]);

                                            if (gx != 0) {
                                                float c = gx - anglex;
                                                if (Math.abs(c) >= accuracy) {
                                                    Log.d("================", "anglex------------>" + (gx - anglex));
                                                    gx = anglex;
                                                }

                                            } else {
                                                gx = anglex;
                                            }
                                            if (gy != 0) {
                                                float c = gy - angley;
                                                if (Math.abs(c) >= accuracy) {
                                                    Log.d("================", "anglex------------>" + (gy - angley));
                                                    gy = angley;
                                                }
                                            } else {
                                                gy = angley;
                                            }
                                            if (gz != 0) {
                                                float c = gz - anglez;
                                                if (Math.abs(c) >= accuracy) {
                                                    Log.d("================", "anglex------------>" + (gy - angley));
                                                    gz = anglez;
                                                }
                                            } else {
                                                gz = anglez;
                                            }

                                        }
                                        timestamp = event.timestamp;
                                        json = new JSONObject();
                                        try {
                                            json.put("x", gx);
                                            json.put("y", gy);
                                            json.put("z", gz);
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }

                                        result = getJson(json);
                                        json = new JSONObject();
                                        try {
                                            json.put("data", result);
                                            json.put("action", "MonitoringUpdateGyro");

                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                        break;
                                }
                            }
                        }

                        @Override
                        public void onAccuracyChanged(Sensor sensor, int accuracy) {

                        }

                    };

                    break;
                case "StopMonitoringGyro":
                    sensorManager.unregisterListener(mSensorEventListener);
                    result = getJson(null);
                    if (callback != null) {
                        callback.onCallBack(result);
                    }
                    break;
                //获取通讯录列表
                case "ObtainAllAddressBook":
                    //                    List<Map<String,String>> contacts = getContacts();
                    //                    for (int i = 0; i <contacts.size() ; i++) {
                    //                        Map<String, String> map = contacts.get(i);
                    //                        map.get()
                    //                    }
                    //                    json = new JSONObject();
                    //                    json.put()
                    break;
                //播放本地音频
                case "PlayNativeSound":
                    try {
                        MediaPlayer player = new MediaPlayer();
                        AssetManager assets = thisActivity.getAssets();
                        String sound = (String) send_data.get("sound");
                        AssetFileDescriptor fileDescriptor = assets.openFd(sound);
                        player.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(),
                                fileDescriptor.getStartOffset());
                        player.prepare();
                        player.start();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    //                    MediaPlayer mediaPlayer = MediaPlayer.create(thisActivity, R.raw.goldvoice1);
                    //                    mediaPlayer.start();
                    break;
                //发短信功能
                case "OpenMessage":
                    JSONArray tels = send_data.getJSONArray("tels");
                    for (int i = 0; i < tels.length(); i++) {
                        phoneNum = tels.getString(i);
                    }
                    String msg = send_data.getString("body");
                    //获得短信管理器
                    SmsManager smsManager = SmsManager.getDefault();
                    //拆分短信内容
                    ArrayList<String> contents = smsManager.divideMessage(msg);
                    json = new JSONObject();
                    //处理返回的发送状态
                    String SENT_SMS_ACTION = "SENT_SMS_ACTION";
                    Intent sentIntent = new Intent(SENT_SMS_ACTION);
                    PendingIntent sentPI = PendingIntent.getBroadcast(thisActivity, 0, sentIntent,
                            0);
                    // register the Broadcast Receivers
                    thisActivity.registerReceiver(new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context _context, Intent _intent) {
                            switch (getResultCode()) {
                                case Activity.RESULT_OK:
                                    Toast.makeText(thisActivity,
                                            "短信发送成功", Toast.LENGTH_SHORT)
                                            .show();
                                    try {
                                        json.put("message", "3");
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                    result = getJson(json);
                                    if (callback != null) {
                                        callback.onCallBack(result);
                                    }
                                    break;
                                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                                    try {
                                        json.put("message", "2");
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                    result = getJson(json);
                                    if (callback != null) {
                                        callback.onCallBack(result);
                                    }
                                    break;
                                case SmsManager.RESULT_ERROR_RADIO_OFF:
                                    try {
                                        json.put("message", "1");
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                    result = getJson(json);
                                    if (callback != null) {
                                        callback.onCallBack(result);
                                    }
                                    break;
                                case SmsManager.RESULT_ERROR_NULL_PDU:
                                    break;
                            }
                        }
                    }, new IntentFilter(SENT_SMS_ACTION));
                    //处理返回的接收状态
                    String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION";
                    // create the deilverIntent parameter
                    Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);
                    PendingIntent deliverPI = PendingIntent.getBroadcast(thisActivity, 0,
                            deliverIntent, 0);
                    thisActivity.registerReceiver(new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context _context, Intent _intent) {
                            Toast.makeText(thisActivity,
                                    "收信人已经成功接收", Toast.LENGTH_SHORT)
                                    .show();
                        }
                    }, new IntentFilter(DELIVERED_SMS_ACTION));
                    for (String text : contents) {
                        smsManager.sendTextMessage(phoneNum, null, text, sentPI, deliverPI);
                    }
                    break;

            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private String getJson(JSONObject json) {
        JSONObject json0 = new JSONObject();
        if (json == null) {
            try {
                json0.put("data", "");
                json0.put("code", "1");
                json0.put("error", "");
            } catch (JSONException e) {
                e.printStackTrace();
            }

        } else {
            try {
                json0.put("code", "0");
                json0.put("error", "");
                json0.put("data", json);
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
        return json0.toString();
    }

    private String getErrorJson(JSONObject json) {
        JSONObject json1 = new JSONObject();
        try {
            json1.put("code", "1");
            json1.put("error", "");
            json1.put("data", json);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return json1.toString();
    }

    /**
     * 判断Android系统版本是否 >= M(API23)
     */
    private boolean isM() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return true;
        } else {
            return false;
        }
    }


    /*
   * 初始化分享弹出框
  */
    private void initShareDialog(final SendMessageToWX.Req req) {
        mShareDialog = new Dialog(thisActivity, R.style.MyDialogStyle);
        mShareDialog.setCanceledOnTouchOutside(true);
        mShareDialog.setCancelable(true);
        Window window = mShareDialog.getWindow();
        if (window != null) {
            window.setGravity(Gravity.BOTTOM);
        }
        View view = View.inflate(thisActivity, R.layout.lay_share, null);
        view.findViewById(R.id.tv_wx_session).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                req.scene = SendMessageToWX.Req.WXSceneSession;
                iwxapi.sendReq(req);
            }
        });
        view.findViewById(R.id.tv_wx_timelie).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                req.scene = SendMessageToWX.Req.WXSceneTimeline;
                iwxapi.sendReq(req);
            }
        });
        view.findViewById(R.id.tv_wx_favorite).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                req.scene = SendMessageToWX.Req.WXSceneFavorite;
                iwxapi.sendReq(req);
            }
        });
        view.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mShareDialog != null && mShareDialog.isShowing()) {
                    mShareDialog.dismiss();
                }
            }
        });
        window.setContentView(view);
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);//设置横向全屏
    }


}
